package com.dagene.weixin.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 
 * 
 * @author zhaomy
 * @date: 2015-11-4 上午10:39:31
 */
public class DateUtil {
	
	static String formats = "yyyy-MM-dd HH:mm:ss";
	static String formatsYMD = "yyyy-MM-dd";
	
	public static String DateToString(Date date) {

		try {
			SimpleDateFormat sdf = new SimpleDateFormat(formats);

			String str = sdf.format(date);
			return str;
		} catch (Exception ex) {
			return "";
		}
	}

	public static String DateToStringYMD(Date date) {

		try {
			SimpleDateFormat sdf = new SimpleDateFormat(formatsYMD);

			String str = sdf.format(date);
			return str;
		} catch (Exception ex) {
			return "";
		}
	}
	
	// Unix时间转化为普通时间
		public static Date UnixTimeToDate(String timestampString) throws Exception {
			try {
				Long timestamp = Long.parseLong(timestampString) * 1000;
				String date = new SimpleDateFormat(formats).format(new Date(
						timestamp));

				return new SimpleDateFormat(formats).parse(date);
			} catch (ParseException e) {

				e.printStackTrace();
			}
			return null;
		}
}
